from blls.file_search_blls.file_search_bll import FileSearchBLL
from handlers.base_handler import BaseHandler
from utils.check_params_utlil import CheckParams
from utils.handler_util import HandlerUtil


class SearchContentHandler(BaseHandler):

    async def post(self):
        required_params = [
            ["query", False, ""],
            ["app_id", True, ""],
            ["scene", False, ""],
            ["sign", True, ""],
            ["top_k",False, 1],
            ["timestamp", True, ""]
        ]
        res_data = CheckParams(params=self.request_data, conditions=required_params).check()
        if not res_data.is_success:
            return self.write(HandlerUtil.set_failure_response(message=res_data.message))
        res = FileSearchBLL(request=self).search(**res_data.data)
        return self.write(HandlerUtil.set_response(data=res.data, message=res.message, is_success=res.is_success))